package jmine.tec.services.utils.replace.transformation;

import jmine.tec.services.utils.replace.api.ServiceBlock;
import jmine.tec.services.utils.replace.api.ServiceRow;

public abstract class AbstractReplaceContentTransformation extends AbstractTransformation {

    protected final String parameter;

    public AbstractReplaceContentTransformation(String action, String name, String parameter) {
        super(action, name);
        this.parameter = parameter;
    }

    public void apply(ServiceBlock block) {
        if (block.getHeader().hasParameter(this.parameter)) {
            for (ServiceRow row : block.getServices()) {
                if (this.acceptServiceRow(row)) {
                    row.putParameter(this.parameter, this.getNewContent(row));
                }
            }
        }
    }

    protected String getParameter() {
        return this.parameter;
    }

    protected abstract boolean acceptServiceRow(ServiceRow row);

    protected abstract String getNewContent(ServiceRow row);
}
